package com.heima.wemedia.controller.v1;

import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author TheCai
 * @date 2021/5/27 15:46
 */
@Api
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
  @Autowired WmMaterialService wmMaterialService;
  // 上传图片
  @ApiOperation("上传图片方法")
  @PostMapping("/upload_picture")
  public ResponseResult uploadPicture(MultipartFile multipartFile) {

    return wmMaterialService.uploadPicture(multipartFile);
  }
  @ApiOperation("查询收藏图片和全部图片")
  @PostMapping("list")
  public ResponseResult findList(@RequestBody WmMaterialDto dto){
    return wmMaterialService.finLlist(dto);
  }
  @ApiOperation("删除图片")
  @GetMapping("del_picture/{id}")
  public ResponseResult delPicture(@PathVariable("id") Integer Id){
    return wmMaterialService.delPicture(Id);
  }

  @GetMapping("/cancel_collect/{id}")
  public ResponseResult cancelCollectionMaterial(@PathVariable("id") Integer id) {
    return wmMaterialService.updateStatus(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
  }
  @GetMapping("/collect/{id}")
  public ResponseResult collectionMaterial(@PathVariable("id") Integer id) {
    return wmMaterialService.updateStatus(id, WemediaConstants.COLLECT_MATERIAL);
  }
}
